<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<%@ include file="/web/header.jsp"%>
</head>
<body>
<fieldset class="layui-elem-field" style="margin: 10px">
			<legend>设置部门</legend>
				<form class="layui-form" lay-filter="formA" action="post">
					<div class="layui-form-item">
						<label class="layui-form-label">编号</label>
						<div class="layui-input-inline">
							<input type="text" name="code" readonly lay-verify="required"
								placeholder="请输入编号" autocomplete="off" class="layui-input">							 
						</div>						
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">部门</label>
						<div class="layui-input-inline">
							<select name ='codeDept'></select>
						</div>
					</div>
					<div class="layui-form-item">
						<div class="layui-input-block">
							<input type="button" value="确定" class="layui-btn" lay-submit lay-filter="setDept"> 								
							<input type="button" value="关闭"class="layui-btn" onclick="layerClose()">	
						</div>						
					</div>
					<input type="hidden" name="action" value="setDept">
				</form>
		</fieldset>
		<script type="text/javascript">
		initSel();
		function initSel(){
			ajax('/DepartmentServlet',{action:'list'},'json',function(data){
				var opt = "<option value=''>请选择部门</option>"
				$.each(data,function(){
					opt += "<option value='"+this.code+"'>"+this.name+"</option>"
				})
				$("select[name='codeDept']").html(opt);
				form.render();
				init()
			})
		}
		var code = '<%=request.getParameter("code")%>';
		function init(){
			ajax("/EmployeeServlet",{action:"get",code:code},'json',function(data){
				form.val("formA",{code:data.code,codeDept:data.codeDept})
			});
		}
		formSubmit('setDept','/EmployeeServlet','text',function(data){
			if(data==1){
				layer.msg("设置成功",{time:1500},layerClose)
			}else{
				layer.msg("设置失败")
			}
		})
		</script>
</body>
</html>